
(function (factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    } else {
        if (typeof module === 'object' && module.exports) {
            //noinspection NpmUsedModulesInstalled
            module.exports = factory(require('jquery'));
        } else {
            factory(window.jQuery);
        }
    }
}(function ($) {
    'use strict';
    var $h, ImageShow;
    $h = {
        replaceTags: function (str, tags) {
            var out = str;
            if (!tags) {
                return out;
            }
            $.each(tags, function (key, value) {
                if (typeof value === 'function') {
                    value = value();
                }
                out = out.split(key).join(value);
            });
            return out;
        },
        initModal: function ($modal) {
            var $body = $('body');
            if ($body.length) {
                $modal.appendTo($body);
            }
        },
        isIE: function (ver) {
            var div, status;
            // check for IE versions < 11
            if (navigator.appName !== 'Microsoft Internet Explorer') {
                return false;
            }
            if (ver === 10) {
                return new RegExp('msie\\s' + ver, 'i').test(navigator.userAgent);
            }
            div = document.createElement('div');
            div.innerHTML = '<!--[if IE ' + ver + ']> <i></i> <![endif]-->';
            status = div.getElementsByTagName('i').length;
            document.body.appendChild(div);
            div.parentNode.removeChild(div);
            return status;
        },

    }

    ImageShow = function (element, options) {
        var self = this;
        self.$element = $(element);
        self.$parent = self.$element.parent();
        if (!self._validate()) {
            return;
        }
        self.isPreviewable = $h.hasFileAPISupport();
        self.isIE9 = $h.isIE(9);
        self.isIE10 = $h.isIE(10);
        if (self.isPreviewable || self.isIE9) {
            self._init(options);
            self._listen();
        }
        self.$element.removeClass('file-loading');
    };

    ImageShow.prototype = {
        _initTemplateDefaults: function () {
            var self = this, tMain1, tMain2, tPreview, tFileIcon, tClose, tCaption, tBtnDefault, tBtnLink,
                tBtnBrowse,
                tModalMain, tModal, tProgress, tSize, tFooter, tActions, tActionDelete, tActionUpload,
                tActionDownload,
                tActionZoom, tActionDrag, tIndicator, tTagBef, tTagBef1, tTagBef2, tTagAft, tGeneric, tHtml, tImage,
                tText, tOffice, tGdocs, tVideo, tAudio, tFlash, tObject, tPdf, tOther, tStyle, tZoomCache,
                vDefaultDim,
                tStats;
            tModalMain = '<div id="' + $h.MODAL_ID + '" class="file-zoom-dialog modal fade" ' +
                'tabindex="-1" aria-labelledby="' + $h.MODAL_ID + 'Label"></div>';
            tModal = '<div class="modal-dialog modal-lg{rtl}" role="document">\n' +
                '  <div class="modal-content">\n' +
                '    <div class="modal-header">\n' +
                '      <h5 class="modal-title">{heading}</h5>\n' +
                '      <span class="kv-zoom-title"></span>\n' +
                '      <div class="kv-zoom-actions">{toggleheader}{fullscreen}{borderless}{close}</div>\n' +
                '    </div>\n' +
                '    <div class="modal-body">\n' +
                '      <div class="floating-buttons"></div>\n' +
                '      <div class="kv-zoom-body file-zoom-content {zoomFrameClass}"></div>\n' + '{prev} {next}\n' +
                '    </div>\n' +
                '  </div>\n' +
                '</div>\n';
        }
    }
    $.fn.imageshow = function (options) {
        if (!$h.isIE(9)) {
            return;
        }




        $(this).on('click', function () {
            var opts = $.extend({}, $.fn.imageshow.defaults, options);
        var viewer = $('<div class="modal fade bs-example-modal-lg text-center" id="bootstrapImageShow" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" >\n' +
            '          <div class="modal-dialog modal-lg" style="display: inline-block; width: auto;">\n' +
            '            <div class="modal-content">\n' +
            '             <img' +
            '\t\t\t class="carousel-inner img-responsive img-rounded img-viewer" \n' +
            '\t\t\t onclick="$(\'#bootstrapImageShow\').modal(\'hide\');setTimeout(function(){$(\'#bootstrapImageShow\').remove();},200);"\n' +
            '\t\t\t onmouseover="this.style.cursor=\'zoom-out\';" \n' +
            '\t\t\t onmouseout="this.style.cursor=\'default\'"  \n' +
            '\t\t\t />\n' +
            '            </div>\n' +
            '          </div>\n' +
            '        </div>');
        $('body').append(viewer);
        if ($(this).attr(opts.src)) {
            $("#bootstrapImageShow").find(".img-viewer").attr("src", $(this).attr(opts.src));
            $("#bootstrapImageShow").modal();
        } else {
            throw "图片不存在"
        }

    })

    $(this).on('mouseover', function () {
        $(this).css('cursor', 'zoom-in');
    })

},

        $.fn.imageshow.defaults = {

        }

$.fn.imageshow.defaults = {
    src: 'src'
}
}));
